Part Number Hot Search : 
U225M CPZRL7 MOC21 HMJ807 10MU10NU EC2C35 0N60C L9341H
Product Description
Full Text Search
 

To Download DS1623 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
   copyright 1995 by dallas semiconductor corporation. all rights reserved. for important information regarding patents and other intellectual property rights, please refer to dallas semiconductor data books. application note 105 high resolution temperature measurement with dallas directtodigital temperature sensors application note 105 slope accumulator counter compare temperature register preset =0 counter =0 preset low temperature coefficient oscillator high temperature coefficient oscillator inc set/clear lsb stop 032796 1/19 introduction this application note describes the principle of opera- tion of dallas semiconductor's line of directtodigital temperature sensors, and outlines a method of achiev- ing high (<0.05 c) resolution with these devices. an example c code listing is given for use with the ds1620. directtodigital temperature sensor principle of operation the dallas directtodigital temperature sensors measure temperature through the use of an onboard proprietary temperature measurement technique. a block diagram of the temperature measurement cir- cuitry is shown in figure 1. each temperature sensor measures temperature by counting the number of clock cycles that an oscillator with a low temperature coefficient goes through during a gate period determined by a high temperature coeffi- cient oscillator. the counter is preset with a base count that corresponds to 55 c. if the counter reaches zero before the gate period is over, the temperature register, which is also preset to the 55 c value, is incremented, indicating that the temperature is higher than 55 c. at the same time, the counter is then preset with a value determined by the slope accumulator circuitry. this cir- cuitry is needed to compensate for the parabolic behav- ior of the oscillators over temperature. the counter is then clocked again until it reaches zero. if the gate period is still not finished, then this process repeats. the slope accumulator is used to compensate for the nonlinear behavior of the oscillators over temperature, yielding a high resolution temperature measurement (0.5 c for almost all the products). this is done by changing the number of counts necessary for the counter to go through for each incremental degree in temperature. to obtain the desired resolution, there- fore, both the value of the counter and the number of counts per degree c (the value of the slope accumula- tor) at a given temperature must be known. temperature measurement circuitry figure 1
application note 105 032796 2/19 increasing temperature resolution most of dallas' directtodigital temperature sensors provide 0.5 c resolution directly. this is accomplished by the device determining whether to set or clear the least significant bit (lsb), based on the actual tempera- ture. the device attempts to keep errors within 1 / 2 lsb, by quantizing different readings into the lsb step size. for example, a part which is ramping up in temperature from 25 c to +26 c, or down in temperature from 10 c to 11 c, would exhibit this behavior: actual temperature set/clear lsb direct reading 25 clear 25 25.1 clear 25 25.2 clear 25 25.3 set 25.5 25.4 set 25.5 25.5 set 25.5 25.6 set 25.5 25.7 set 25.5 25.8 clear 26 25.9 clear 26 26 clear 26 10 clear 10 10.1 clear 10 10.2 clear 10 10.3 set 10.5 10.4 set 10.5 10.5 set 10.5 10.6 set 10.5 10.7 set 10.5 10.8 clear 11 10.9 clear 11 11 clear 11 this example shows then that every reading is rounded up (in absolute value) by 1 / 2 lsb. for most parts, this is 0.25 c. this is important to remember, since in doing calculations to achieve higher resolutions, this rounding factor must be taken into account. with the exception of devices intended for battery man- agement (ds2434 and ds2435), the temperature sen- sors can measure temperature over the range of 55 c to +125 c in 0.5 c increments. for fahrenheit usage, a lookup table or conversion factor must be used. higher resolutions may be obtained by reading the tem- perature and truncating the least significant bit from the read value. from the example above, it should be apparent that this must be done on the raw, 9bit num- ber, in two'scomplement arithmetic, in order for the correct reading to result. after the truncation, the num- ber can then be converted into a signed integer. this value is referred to below as temp_read. the value left in the counter can then be read by issuing a special command protocol to the sensor. this value is the count remaining (count_remain) after the gate period has ceased. reading the value of the slope accumulator (by using another command protocol or set of protocols, as outlined below) yields the number of counts per degree c ( count_per_degree) at that temperature. once these parameters are all known, the actual tem- perature can be calculated from the following equation: count_per_degree temperature=temp_read 1 / 2 lsb+(count_per_degreecount_remain) a simple routine in c, called calchirestemp, is given in the listing of figure 7. procedures for reading counter values and calculating high resolution temperature readings the following is a list of procedures for performing high resolution temperature readings from various digital thermometers. for all parts, conversions must be done in oneshot mode (if applicable). xxh refers to the proto- col to send to the part; if two protocols are listed together (e.g., 84h a0h), both protocols should be sent in the given order, without resetting the part between proto- cols. a variable name xxx is designated as anamed xxx.o
application note 105 032796 3/19 note: the highresolution temperature equation is slightly dif- ferent for the ds1821 as compared to the ds1620, DS1623, ds1625, ds2434, and ds2435. ds1620, DS1623, and ds1625 1. issue start convert protocol (eeh). 2. when conversion is finished, read 9bit temperature value (aah). 3. truncate halfdegree bit from reading. 4. convert truncated value from 2's complement to signed integer (named temp_read). 5. read 9bit counter value (a0h; named count_remain). 6. send undocumented load counter protocol (41h). 7. read 9bit counter value (a0h; named count_per_degree). 8. calculate highresolution temperature using the high resolution temperature equation given in the previous section. 1 / 2 lsb = 0.25. ds1621, ds1624, and ds1820 the procedure to find the high resolution temperature parameters and the calculation to use are given in the respective product data sheets for these products. note that since the ds1624 already provides a 13bit number with 0.03125 c resolution, no further proces- sing is possible to achieve any higher temperature reso- lution. ds1821 1. issue start convert protocol (eeh). 2. when conversion is finished, read 8bit temperature value (aah). 3. convert value from 2's complement to signed inte- ger (named temp_read). 4. read 9bit counter value (a0h; named count_remain). 5. send undocumented load counter protocol (41h). 6. read 9bit counter value (a0h; named count_per_degree). 7. calculate highresolution temperature using the high resolution temperature equation given in the previous section. note that for the ds1821, 1/2lsb = 0.5. ds2434 and ds2435 1. issue start convert protocol (d2h). 2. when conversion is finished, read 8bit temperature value (b2h 61h). 3. convert temperature value from 2's complement to signed integer (named temp_read). 4. read 9bit counter value (84h a0h; named count_remain). 5. send undocumented load counter protocol (84h 41h). 6. read 9bit counter value (84h a0h; named count_per_degree). 7. calculate highresolution temperature using the high resolution temperature equation given in the previous section. 1 / 2 lsb = 0.25. example c code the following example is a simple exerciser for the ds1620 from an ibmpc compatible computer. it reads temperature and displays it in both the normal 0.5 c resolution and in high resolution. the ds1620 is inter- faced to the parallel port of the pc using the circuit shown in figure 2, which is the schematic of the ds1620k demo kit. the hardware for the ds1620k demo kit astealso power from a parallel port using d1, d2, d3, and c3. not all pc parallel ports are able to supply sufficient current to make this hardware work, so be advised that if this cir- cuit does not work, try connecting a +5v power source to the +5v line in this circuit and try again. r1 and c1 serve to filter the clk line and prevent negative under- shoots. likewise, c2 helps prevent negative under- shoot on the dq line. the code is written in an attempt to make it easy to adapt to any of the digital temperature sensors. all that need be done to use it with other devices is to change the command header file to account for the protocols and resolution of the device being used, and change the files which manipulate the hardware interface to the device to account for either 1, 2 or 3wire interfaces.
application note 105 032796 4/19 ds1620k hardware schematic figure 2 j1 db25 male gnd data4 sel in data3 1 14 2 15 3 16 4 17 5 18 6 19 7 20 8 21 9 22 10 23 11 24 12 25 13 d1 d2 d3 +5v r1 220 c1 390 pf c2 390 m f c3 10 m f dq clk/conv rs t gnd vdd th tl tcom 1 2 3 4 8 7 6 5 u1 ds1620
application note 105 032796 5/19 threewir.h c code listing figure 3 /* threewir.h this file defines the method for setting the 3wire interface lines from an ibmpc compatible computer. the interface is through the parallel port. the parallel port lines used are as follows: /selin pin 17 dq data4 pin 5 clk data3 pin 4 /rst gnd pin 18 gnd the inportb, outportb, and delay functions are defined in most pcbased c compil- ers in dos.h */ #include #define clk_hi p_data|= 0x08; outportb(p_addr,p_data); delay(1); #define clk_low p_data&=~0x08; outportb(p_addr,p_data); delay(1); #define rstb_hi p_data|= 0x04; outportb(p_addr,p_data); delay(1); #define rstb_low p_data&=~0x04; outportb(p_addr,p_data); delay(1); #define dq_hi outportb(p_addr+2,0x02); delay(1); #define dq_low outportb(p_addr+2,0x0a); delay(1); #define read_back ((inportb(p_addr+2) & 0x08) >> 3)+1 #define p_addr peek(0,0x0408) /* finds the address of the parallel port */ char p_data = 0xff;
application note 105 032796 6/19 ds3wire.c c code listing figure 4 /* ds3wire.c these routines handle a dallas 3wire interface. methods of changing the individ- ual bit states in the hardware need to be defined in othreewir.ho. */ #include othreewir.ho /* bit level drivers, used in routines for handling the protocol and data interface to a 3wire device. */ /* drives rstb signal high (state=1) or low (state=0) */ void rb3w( int state ) { if (state==0) {rstb_low;} else {rstb_hi} } /* drives clk signal high (state=1) or low (state=0) */ void c3w( int state ) { if (state==0) {clk_low} else {clk_hi} } /* drives dq signal high (state=1) or low (state=0) */ void dq3w( int state ) { if (state==0) {dq_low} else {dq_hi} } /* reads data back from port */ int rd_back() { char i; i=read_back; return( i ); }
application note 105 032796 7/19 /* writes a 0 (w_bit=0) or a 1 (w_bit=1) to a three wire device. */ void write_bit( int w_bit ) { if ( w_bit == 0 ) dq3w( 0 ); else dq3w( 1 ); c3w( 0 ); c3w( 1 ); dq3w( 1 ); } /* reads a 0 (return 0) or a 1 (return 1) from a three wire device. */ int read_bit() { int i; c3w( 0 ); i=rd_back(); c3w( 1 ); return(i); } /* routines to read and write a dallas 3wire part. the three wire interface typi- cally requires that the part be sent an eightbit protocol, followed by data. the exception to this are the digital potentiometers, which use no protocols but send only data. all transfers are lsb first. if writing, the data must follow the protocol immediately, but there is no fixed number of bits that may be data. if reading, the part must be written with an eight bit protocol; the dq pin must then be changed to read back data. as with writing, there is no fixed number of bits that may be data. these routines are set up to handle an arbitrary data length up to the size of an int (which is typically 16 bits for most c compilers). */
application note 105 032796 8/19 /* write_part write a command and data to a 3wire part. param is the integer value of the data to be written after the write protocol. n_bits is the number of bits to transfer in param. */ void write_part(int protocol, int param, int n_bits) { int index,data; rb3w(1); /* raise the /rst line */ for (index = 0; index<8; index++) /* protocol is 8 bits */ { data = protocol>>index; data &= 0x01; write_bit(data); } for (index = 0; index>index; data &= 0x01; write_bit(data); } rb3w(0); /* drop /rst line */ } /* read_part reads data from a 3wire part. protocol is command to be written to the part, and n_bits is number of bits to read after the protocol is sent. returns int value of reading. */ int read_part(int protocol, int n_bits) { int index,data; int r_data = 0; rb3w(1); /* raise the /rst line */ for (index = 0; index<8; index++) /* protocol is 8 bits */ { data = protocol>>index; data &= 0x01; write_bit(data); } for (index = 0; index application note 105 032796 9/19 ds1620cmd.h figure 5 /* 1620cmd.h this file defines the protocols and bit masks needed for a specific device: the ds1620. */ /* protocols */ #define read_temp 0xaa #define start_convert 0xee #define stop_convert 0x22 #define write_th 0x01 #define write_tl 0x02 #define read_th 0xa1 #define read_tl 0xa2 #define write_config 0x0c #define read_config 0xac #define read_counter 0xa0 #define load_counter 0x41 /* masks for configuration/status register */ #define mode_mask 0x03 /* masks off all but cpu and 1shot bits */ #define nvb_mask 0x10 /* masks off all but nvb bit */ #define done_mask 0x80 /* masks off all but done bit */ #define flags_mask 0x60 /* masks off all but thf and tlf flag bits */ #define flag_offset 5 /* number of right shifts to rightjustify flags */ #define res (int)(1.0/lsb) /* resolution factor, used in application to calculate actual temperatures from raw data */ float lsb = 0.5; /* the value of a lsb on the ds1620 in degrees c */
application note 105 032796 10/19 devfunc.c c code listing figure 6 /* device specific functions these are device specific functions for all 3wire dallas temperature sensors, supporting all documented functions of the parts, including high resolution tem- perature measurements. since these routines may be used with many different devices, no attempt is made in these routines to interpret the data written or read; the application program which uses these routines must assure that the data written or read is in the appropriate format for use by these routines and by the application. */ /* place deviceappropriate include file here for specific device commands. */ #include #include o1620cmd.ho /* this example for ds1620 */ /*prototypes*/ extern void write_part(); extern int read_part(); /* starttempconvert this routine issues the start convert command. no further data is required and no data is read back. */ void starttempconvert(void) { write_part(start_convert,0,0); } /* stoptempconvert this routine isses the stop convert command. no further data is required and no data is read back. */ void stoptempconvert(void) { write_part(stop_convert,0,0); }
application note 105 032796 11/19 /* readtemp this routine reads back the value of the converted temperature reading and returns that value. num_bits is the number of bits to read back (up to size of int (16)). remember that this only returns the raw data; the calling program must know how to interpret the data (for example, this routine will return an int with 9 bits when called as readtemp(9); the user must then know that the lsb is 0.5 c, and make the appropriate data conversion. likewise, interpreting the sign of the returned tem- perature is up to the calling program.) */ int readtemp (int num_bits) { int temperature; temperature = read_part(read_temp,num_bits); return(temperature); } /* writetemphigh this routine writes to the th thermostat register. param is value to place in th, and should be 9 bits wide. as with readtemp, the calling program must assure that the data sent here is in the appropriate devicespecific data form to be used properly (is lsb 0.5 c or 1 c?, etc). */ void writetemphigh (int param, int num_bits) { write_part(write_th,param,num_bits); } /* writetemplo this routine writes to the tl thermostat register. param is value to place in tl, and should be num_bits bits wide. as with readtemp, the calling program must assure that the data sent here is in the appropriate devicespecific data form to be used properly (is lsb 0.5 c or 1 c?, etc). */ void writetemplo (int param, int num_bits) { write_part(write_tl, param, num_bits); } /* readtemphigh this routine reads back from the part the value stored in the th thermostat regis- ter and returns that value. num_bits is the number of bits to read back (up to size of int (16)). remember that this only returns the raw data; the calling pro- gram must know how to interpret the data (for example, this routine will return an int with 9 bits when called as readtemphigh(9); the user must then know that the lsb is 0.5 c, and make the appropriate data conversion. likewise, interpreting the sign of the returned temperature is up to the calling program.) */ int readtemphigh (int num_bits) {
application note 105 032796 12/19 int thigh; thigh = read_part(read_th,num_bits); return(thigh); } /* readtemplo this routine reads back from the part the value stored in the tl thermostat regis- ter and returns that value. num_bits is the number of bits to read back (up to size of int (16)). see the caveat for readtemphigh regarding returned data. */ int readtemplo (int num_bits) { int tlow; tlow = read_part(read_tl,num_bits); return(tlow); } /* loadcounter this routine sends the load counter command. no further data is required and no data is read back. */ void loadcounter (void) { write_part(load_counter,0,0); } /* readcounter this routine reads back from the part the value in the temp sensor count register and returns that value. num_bits is the number of bits to read back (up to size of int (16)). */ int readcounter (int num_bits) { int count; count = read_part(read_counter,num_bits); return(count); }
application note 105 032796 13/19 /* writeconfig this routine writes to the configuration register. param is the byte to be written into the configuration register, and it is always 8 bits wide. */ void writeconfig (int param) { write_part(write_config,param,8); } /* readconfig this routine reads back the value of the configuration byte and returns that value. it always returns 8 bits. */ int readconfig(void) { int regvalue; regvalue = read_part(read_config,8); return(regvalue); } /* checkifbusy this routine will check to see if the device is busy and cannot process further writes to eeprom. it checks the nvb flag in the configuration register. if the device is busy, the function returns a 1; if it is not busy, the function will return a 0. */ int checkifbusy(void) { if ((readconfig() & nvb_mask) == nvb_mask) return(1); else return(0); } /* checkifdone this routine will check to see if the device has completed a temperature conver- sion. it checks the done flag in the configuration register. if the device is busy, the function returns a 1; if it is not busy, the function will return a 0. note: if the mode is set so that the temp sensor is doing continuous conversions, done will never be set, so make sure you know what mode you're in if you use this check routine. */ int checkifdone(void) { if ((readconfig() & done_mask) == done_mask) return(0); else return(1); }
application note 105 032796 14/19 /* setmode this routine sets the operating mode of the digital temperature sensor. mode is determined by two bits in the configuration register: cpu and 1shot. the following modes are possible: mode cpu 1shot 1 0 0 standalone, continuous conversions (typical for thermostat) 2 0 1 standalone, one shot (used only if conversions can be started by conv pin) 3 1 0 cpu, continuous conversion (typical for thermostat with readback) 4 1 1 cpu, one shot (typical for lowpower temp readings) this routine will set the configuration register bits appropriately for the mode value passed to the routine in mode. it returns no data. */ void setmode(int mode) { writeconfig (mode1); } /* readflags this routine will read the state of the two temperature flags, thf and tlf. it returns an integer, t_flag, which is the number of the two bits (0 = 00, 1=01, 2=10, 3=11). */ int readflags(void) { int t_flag; t_flag =( readconfig() & flags_mask) >> flag_offset; return(t_flag); }
application note 105 032796 15/19 simple ds1620 exerciser c code listing figure 7 /* ds1620 exerciser example program to show how to perform various functions of a ds1620 digital ther- mometer. this example is consoledriven; that is, it expects input from the user via a console interface, to set the mode and th, tl register values. */ #include #include odevfunc.co #include ods3wire.co /*prototypes*/ void starttempconvert(void); void stoptempconvert(void); int readtemp(int); void writetemphigh(int,int); void writetemplo(int,int); int readtemphigh(int); int readtemplo(int); void loadcounter(void); int readcounter(int); void writeconfig(int); int readconfig(void); int checkifbusy(void); int checkifdone(void); void setmode(int); int readflags(void); void inittempsensor(void); void setthermostat(void); float calchirestemp(int,int,int); /* inittempsensor this routine will initialize the temperature sensor to a mode specified by the user. */ void inittempsensor(void) { int mode, test; printf(o1. standalone mode, continuous conversions\no); printf(o2. standalone mode, one shot\no); printf(o3. cpu mode, continuous conversions\no); printf(o4. cpu mode, one shot\no); printf(oenter mode desired:o); scanf(o%do,&mode); setmode(mode); /*write mode bits to config register */
application note 105 032796 16/19 do /* wait until eeprom write complete */ { test = checkifbusy(); printf(odevice busyo); } while (test); } /* setthermostat this routine sets the thermostat registers to the high and low values specified by the user. */ void setthermostat(void) { float t_hi, t_lo, high_t, low_t; /* since th and tl are 9bit numbers with a 0.5 c lsb, they must be of type float. this program must then assure the data passed to the other routines is formatted properly. */ int hi_t, lo_t, busy; printf(oenter a high temperature limit:o); scanf(o%fo,&t_hi); /* get th limit */ printf(oenter a low temperature limit:o); scanf(o%fo,&t_lo); /* get tl limit */ hi_t = res*t_hi; /* turn into a 9bit integer note that this routine does not check to see if the user enters some number that can't be used, like 22.635. an actual application would want to do such error trap ping. */ writetemphigh(hi_t,9); /* write to th register*/ do /* wait until eeprom write complete */ { busy = checkifbusy(); printf(odevice busyo); } while (busy);
application note 105 032796 17/19 lo_t= res*t_lo; /* same comments as for th */ writetemplo(lo_t,9); /* write to tl register */ do /* wait until eeprom write complete */ { busy = checkifbusy(); printf(odevice busyo); } while (busy); } /* calchirestemp this routine handles the calculation of temperature in high resolution mode. requires that the part has provided the values of temperature, count_per_degree, and count_remain. this routine assumes 9 bit data is read back, and that the user has defined the value of lsb and res in the appropriate dsxxxxcmd.h file. */ float calchirestemp(int temp9, int count_per_degree, int count_remain) { int temp_read; float frac_deg; temp_read = temp9/res; /* temp9 is raw data convert for lsb value */ if(temp_read>>8>0) /* check to see if msb set works for 9bit data. */ temp_read =256; /* convert to negative temper ature */ if(count_per_degree !=0) frac_deg = (count_per_degreecount_remain)/((float)count_per_degree); else frac_deg = lsb/2.0; return(((float)temp_read(lsb/2.0))+frac_deg); } void main(void) { signed int temperature; float read_temp; int countrem,countc; float hires_temp; int busy,key;
application note 105 032796 18/19 inittempsensor(); /* initialize sensor with mode bits */ setthermostat(); /* load in thermostat values, if used */ starttempconvert(); /* start temperature conversion(s) */ switch(readconfig()& mode_mask) /* checks for conversion done. this switch is used to determine what to do depending upon the mode the ds1620 is in. if continuous conversions are going on, temperature readings should only be made periodically based on time. if oneshot mode is used, then you can poll the status register for the done bit to set. */ { case 0: /* continuous conversions so read based on time */ delay(1000); break; case 1: /* one shot mode poll status register for done bit */ do { busy =checkifdone(); printf(o\nconversion in progesso); }while(busy); break; case 2: /* continuous conversions so read based on time */ delay(1000); break; case 3: /* one shot mode poll status register for done bit */ do { busy =checkifdone(); printf(o\nconversion in progesso); }while(busy); break; }/* end switch */
application note 105 032796 19/19 read_temp = (float)readtemp(9)*lsb; /* reads temperature and con verts for lsb value */ if ((int)read_temp>>7>0) /* check if msb set */ read_temp =256; /* if it is, correct for it */ printf(o\nthe temperature is:%5.2fo,read_temp); /* prints temperature on console, to 0.5 c resolution */ stoptempconvert(); /* in case you were previously in continuous mode, stop */ setmode(4); /* must be in oneshot to do high res */ starttempconvert(); /* start temperature conversion(s) */ do /* check to see when conver sion completes by polling done bit */ { busy =checkifdone(); printf(o\nconversion in progesso); }while(busy); read_temp = (float)readtemp(9); /* get raw 9bit temperature data */ if ((int)read_temp>>8>0) /* check if msb set */ read_temp =512; /* if it is, correct for it 9 bits now! */ temperature = (signed int) read_temp; /* make sure temp is now a signed integer */ countrem = readcounter(9); /* reads count remaining */ loadcounter(); /* loads counter reg with counts per degree */ countc = readcounter(9); hires_temp = calchirestemp(temperature,countc,countrem); printf(o\n the temperature is :%5.2fo,hires_temp); /* prints temperature on console, to 0.01 c resolution */ }


▲Up To Search▲   

 
Price & Availability of DS1623

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X